<?php
class Tourism_goods_category_additive_model extends BZ_Model
{
    protected $table = 'tourism_goods_category_additive';
    
    public function total($cid = 0)
    {
        $this->db->where('category_id', $cid);
        $this->db->where('status', 1);
        return $this->db->count_all_results($this->table);
    }

    public function page_list($page_num, $num, $param = array())
    {
        if (!isset($param['category_id'])) {
            return;
        }
        $this->db->where('category_id', $param['category_id']);
        $this->db->where('status', 1);
        $this->db->limit($page_num, $num);
        return $this->db->get($this->table);
    }

    /*
     * 附加属性增加
     * */
    public function add($cid, $postData)
    {
        $data = array(
            'category_id' => $cid,
            'name' => $postData['name']
        );
        $this->db->insert($this->table, $data);
        return $this->db->insert_id();
    }

    /*
     * 根据id获取附加属性信息
     * */
    public function getAdditiveById($id)
    {
        $this->db->where('id', $id);
        return $this->db->get($this->table)->row();
    }

    /*-----------------------------*/
    public function updateBak($id, $param)
    {
        $this->db->where('id', $id);
        return $this->db->update($this->table, $param);
    }

    public function getAdditive($category_id)
    {
        $this->db->where('category_id', $category_id);
        return $this->db->get($this->table);
    }

}